/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddProductPanel.java
 *
 * Created on Feb 22, 2011, 12:55:16 PM
 */

package POSTApp;
import Transaction.TransactionItem;

/**
 * GUI panel for selecting a product and quantity.
 * @author Rebecca Bettencourt
 */
public class ProductPanel extends javax.swing.JPanel {

    /** Creates new form AddProductPanel */
    public ProductPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        upcLabel = new javax.swing.JLabel();
        qtyLabel = new javax.swing.JLabel();
        qtyNumber = new javax.swing.JTextField();
        upcNumber = new javax.swing.JTextField();

        upcLabel.setText("UPC:");

        qtyLabel.setText("Quantity:");

        qtyNumber.setText("1");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(upcLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(upcNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(qtyLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(qtyNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(upcLabel)
                .add(upcNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(qtyNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(qtyLabel))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel qtyLabel;
    private javax.swing.JTextField qtyNumber;
    private javax.swing.JLabel upcLabel;
    private javax.swing.JTextField upcNumber;
    // End of variables declaration//GEN-END:variables

    public int getUPC() {
        return Integer.parseInt(upcNumber.getText());
    }

    public int getQuantity() {
        return Integer.parseInt(qtyNumber.getText());
    }

    public TransactionItem getTransactionItem() {
        return new TransactionItem(getUPC(), getQuantity());
    }

    public void clear() {
        upcNumber.setText("");
        qtyNumber.setText("");
    }
}
